package com.example.ruihuada.widget.webEditor

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ObjectAnimator
import android.view.View
import android.widget.LinearLayout

class EditorUtil {
    companion object {
        fun showToolBar(toolbarLayout: LinearLayout) {
            if (toolbarLayout.visibility == View.VISIBLE) {
                return
            }
            toolbarLayout.post {
               // toolbarLayout.visible()
                val end = toolbarLayout.measuredHeight.toFloat()
                val objectAnimator = ObjectAnimator.ofFloat(toolbarLayout, "translationY", end, 0f)
                objectAnimator.duration = 300
                objectAnimator.start()
            }
        }

        fun hideToolBar(toolbarLayout: LinearLayout) {
            if (toolbarLayout.visibility == View.GONE) {
                return
            }
            toolbarLayout.post {
                val end = toolbarLayout.measuredHeight.toFloat()
                val objectAnimator = ObjectAnimator.ofFloat(toolbarLayout, "translationY", 0f, end)
                objectAnimator.duration = 300
                objectAnimator.addListener(object : AnimatorListenerAdapter() {
                    override fun onAnimationEnd(animation: Animator) {
                      //  toolbarLayout.gone()
                    }
                })
                objectAnimator.start()
            }
        }
    }
}